/**
 * Created by Administrator on 2015/4/22.
 */
var utility = (function(){

    var _isAndroid = function () {
        return /android/i.test(navigator.userAgent);
    }

    var _isiPhone = function () {
        return /iphone/i.test(navigator.userAgent);
    }

    var _getQueryString = function(){
        return JSON.parse("{\""+window.location.search.substr(1).split("&").toString().replace(/,/g, "\",\"").replace(/=/g, "\":\"")+"\"}");
    }

    var _readAsDataURL = function (file, onloadevent) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            if (typeof onloadevent == "function"){
                onloadevent(this.result);
            }
        };
    }

    function imageCenterProcess(image, imageContainer) {
        var $image = $(image);
        var imgWidth = $image.width(), imgHeight = $image.height();
        $image.width("auto").height("auto").css("position", "relative");
        var box = $image.closest(imageContainer);
        var scaling = imgWidth / imgHeight;
        var zoomHeight = box.width() / scaling;
        if (zoomHeight > box.height()) {
            $image.width(box.width());
            $image.css("top", (0 - (imgHeight - box.height()) / 2) + "px");
            $image.css("left", 0);
        } else {
            $image.height(box.height());
            $image.css("top", 0);
            $image.css("left", (0 - (imgWidth - box.width()) / 2) + "px");
        }
        $image.attr("center", "center");
    }

    var _readAsDataURL = function (file, onloadevent) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            onloadevent && onloadevent(this.result);
        };
    }

    return{
        isAndroid: _isAndroid,
        isiPhone: _isiPhone,
        getQueryString: _getQueryString,
        readAsDataURL: _readAsDataURL
    }
})();

$(function ($) {

});